import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, App } from 'ionic-angular';
import { UiserviceProvider } from '../../providers/uiservice/uiservice';
import { BusiserviceProvider } from '../../providers/busiservice/busiservice';

/**
 * Generated class for the QzzlistPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-qzzlist',
  templateUrl: 'qzzlist.html',
})
export class QzzlistPage {
  qzzlist=[];
  searchtext:any;
  constructor(public navCtrl: NavController, public navParams: NavParams,
    public appCtrl: App, public busi: BusiserviceProvider,private uiservice: UiserviceProvider) {
    this.getqzzList();
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad QzzlistPage');
  }

  private getqzzList(){
    this.uiservice.showLoading();
    this.busi.getqzzlist().subscribe(
      data => {
        this.uiservice.hideLoading();
        if (data._success) {
          this.qzzlist = data.result;
        } else {
          this.uiservice.showAlert(data._message);
        }
      },
      error => {
        this.uiservice.hideLoading();
        this.uiservice.showAlert("Net Error");
      }
    )
  }
  private qzzdetail(qzz){
    this.navCtrl.push("QzzdetailPage",{qzz:qzz});
  }
  private exit(){
    this.appCtrl.getRootNav().setRoot("LoginChoicePage");
  }
  searchqzz(){
    if(this.searchtext == null){
      this.searchtext = "";
    }
    this.uiservice.showLoading();
    this.busi.qzzquery(this.searchtext).subscribe(
      data=>{
        this.uiservice.hideLoading();
        if(data._success){
          this.qzzlist = data.result;
        }else{
          this.uiservice.showAlert(data._message);
        }
      },
      error=>{
        this.uiservice.hideLoading();
        this.uiservice.showAlert("Net Error");
      }

    );
  }
}
